package main

import (
	"changeme/func/barrage"
	"changeme/func/gamestore"
	"changeme/func/home"
	"changeme/func/navigation"
	"changeme/packge/auxiliary"
	"embed"

	"github.com/wailsapp/wails/v2"
	"github.com/wailsapp/wails/v2/pkg/options"
	"github.com/wailsapp/wails/v2/pkg/options/assetserver"
	"github.com/wailsapp/wails/v2/pkg/options/windows"
)

//go:embed all:frontend/dist
var assets embed.FS

func main() {
	// 打开互斥体
	handler, _ := auxiliary.OpenMutex("锋芒BOX")
	if handler != 0 {
		//弹出信息框 来提示用户
		//messagebox.ShowMessage("重复运行", "已经有一个进程正在运行了，请勿重复运行！")
		////退出程序
		//os.Exit(0)
	}
	// 创建互斥体
	auxiliary.CreateMutex("锋芒BOX")
	app := NewApp()
	homeee := home.NewHome()
	gamestoreeee := gamestore.NewGameStore()
	navigationnn := navigation.NewNavigation()
	barrageeeeee := barrage.NewGameStore()

	// Create application with options
	err := wails.Run(&options.App{
		Title:  "羽鸿互娱",
		Width:  1460,
		Height: 870,
		//禁止调整窗口尺寸
		DisableResize: false,
		//无边框
		Frameless: true,
		AssetServer: &assetserver.Options{
			Assets: assets,
		},
		BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1},
		OnStartup:        app.startup,
		Bind: []interface{}{
			app,
			homeee,
			navigationnn,
			gamestoreeee,
			barrageeeeee,
		},
		SingleInstanceLock: &options.SingleInstanceLock{
			UniqueId:               "c9c8fd93-6758-4144-87d1-34bdb0a8bd60",
			OnSecondInstanceLaunch: app.onSecondInstanceLaunch,
		},
		//Windows设置
		Windows: &windows.Options{
			//禁用GPU加速
			WebviewGpuIsDisabled: true,
			//禁用滑动手势
			EnableSwipeGestures: false,
			//配色
		},
	})

	if err != nil {
		println("Error:", err.Error())
	}
}
